package cn.yayatao.tools.apollo.mybatis.generator;

import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.GeneratedJavaFile;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.JavaFormatter;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.DefaultJavaFormatter;
import org.mybatis.generator.api.dom.java.CompilationUnit;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.java.Parameter;

public class ServicePlugin extends PluginAdapter {
	

	@Override
	public boolean validate(List<String> warnings) {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.mybatis.generator.api.PluginAdapter#contextGenerateAdditionalJavaFiles(org.mybatis.generator.api.IntrospectedTable)
	 */
	public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
		Interface compilationUnit = new Interface(new FullyQualifiedJavaType("cn.coollf.Mars"+introspectedTable.getTableConfiguration().getDomainObjectName())); 
		compilationUnit.addImportedType( new FullyQualifiedJavaType("com.base.sm.Apsy"));
		Method ms = new Method("addPost");
		ms.addParameter(new Parameter(new FullyQualifiedJavaType("com.base.ooo.sm.Apsy"), "sa"));
		compilationUnit.addMethod(ms);
		JavaFormatter javaFormatter = new DefaultJavaFormatter();
		GeneratedJavaFile serverFile = new GeneratedJavaFile(compilationUnit, "out/test", javaFormatter);
		
		
		List<GeneratedJavaFile> out = new ArrayList<>();
		out.add(serverFile);
		return out;
	}

}
